﻿using Newtonsoft.Json;
using System.Text.RegularExpressions;

namespace Leo.Common.Json
{
    public class StringMaskConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof(string) == objectType;
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            return reader.Value;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                return;
            }
            string text = value.ToString();
            string text2 = "[0123456789〇一二三四五六七八九零壹贰叁肆伍陆柒捌玖①②③④⑤⑥⑦⑧⑨]{5,}";
            string text3 = Regex.Replace(text, text2, "****");
            writer.WriteValue(text3);
        }
    }
}
